package edu.moravian.world;

import edu.moravian.math.Point2D;

/**
 * A wrapper class for properties about a rectangular world.
 *
 * @author Elliot
 */
public class WorldDescriptor
{
    Point2D lowerLeft;
    Point2D upperRight;

    /**
     * The two most important aspects of the world dimensions are the lower left
     * and upper right corner. From those two points all other dimension
     * information can be extracted. The world must be rectangular
     *
     * @param lowerLeft the lower left point of the world
     * @param upperRight the upper right point of the world
     */
    public WorldDescriptor(Point2D lowerLeft, Point2D upperRight)
    {
        //ensure the lower left is actually lower and left of the upper right point
        if(lowerLeft.getX() > upperRight.getX())
        {
            throw new IllegalStateException("Lower left point of world must be left of upper right point");
        }
        
        if(lowerLeft.getY() > upperRight.getY())
        {
            throw new IllegalStateException("Lower left point of world must be lower than upper right point");
        }
        
        this.lowerLeft = lowerLeft;
        this.upperRight = upperRight;
    }




    /**
     * Get the smallest x position in the world
     *
     * @return min x
     */
    public double getMinX()
    {
        return lowerLeft.getX();
    }




    /**
     * Get the largest x position in the world
     *
     * @return max x
     */
    public double getMaxX()
    {
        return upperRight.getX();
    }




    /**
     * Get the smallest y position in the world
     *
     * @return min y
     */
    public double getMinY()
    {
        return lowerLeft.getY();
    }




    /**
     * Get the largest y position in the world
     *
     * @return max y
     */
    public double getMaxY()
    {
        return upperRight.getY();
    }




    /**
     * Get the upper left point of the world
     *
     * @return the upper left point of the world
     */
    public Point2D getUpperLeft()
    {
        return new Point2D(lowerLeft.getX(), upperRight.getY());
    }




    /**
     * Get the upper right point of the world
     *
     * @return the upper right point of the world
     */
    public Point2D getUpperRight()
    {
        return new Point2D(upperRight);
    }




    /**
     * Get the lower right point of the world
     *
     * @return the lower right point of the world
     */
    public Point2D getLowerRight()
    {
        return new Point2D(upperRight.getX(), lowerLeft.getY());
    }




    /**
     * Get the lower left point of the world
     *
     * @return the lower left point of the world
     */
    public Point2D getLowerLeft()
    {
        return new Point2D(lowerLeft);
    }




    /**
     * Get the center point of the world
     *
     * @return the center point of the world
     */
    public Point2D getCenter()
    {
        double centerX = (lowerLeft.getX() + upperRight.getX() ) / 2.0;
        double centerY = (lowerLeft.getY() + upperRight.getY()) / 2.0;

        return new Point2D(centerX, centerY);
    }




    /**
     * Get the width of the world
     *
     * @return world width
     */
    public double getWidth()
    {
        return getMaxX() - getMinX();
    }




    /**
     * Get the height of the world
     *
     * @return world height
     */
    public double getHeight()
    {
        return getMaxY() - getMinY();
    }




}



